633A - Ebony and Ivory - CodeForces Solution


brute force math number theory *1100

Please click on ads to support us..

Python Code:

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)

f = 0

for i in range(10000):
    ai= a*i

    if ai>c:
      break
  
    remaining= c-a*i

    if remaining%b==0:
      print("YES")
      f= 1
      break

if f == 0:
    print("NO")

   					 		   	   					 	 				

C++ Code:

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<cctype>
#include<set>
#include<unordered_set>
#include<cstring>
#include<numeric>
#include<limits>
#include<limits.h>
#include<bitset>
#include<list>
using namespace std;
#define ll long long
#define pb push_back
#define Fifo ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int c2=c;
    while(c>0)
    {

        if(c%b==0)
        {
            cout<<"Yes";
            return 0;
        }
        c-=a;
    }
    while(c2>0)
    {

        if(c2%a==0)
        {
            cout<<"Yes";
            return 0;
        }
        c2-=b;
    }
    cout<<"No";
}




























































bool isPrime(ll n) {
    if (n <= 1)
        return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0)
            return false;

    return true;
}
// function to find a substring in a string
int isSubstring(string s1, string s2)
{
    if (s2.find(s1) != string::npos)
        return s2.find(s1);
    return -1;
}
//function to find gcd using Euclid's algorithm
int gcd(int n1, int n2)
{
    if (n2 != 0)
        return gcd(n2, n1 % n2);
    else
        return n1;
}
// Function to find gcd of array of n numbers
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
    {
        result = gcd(arr[i], result);

        if (result == 1)
        {
            return 1;
        }
    }
    return result;
}
//function return the number of distinct characters in a string O(s.length())
int function(string s)
{
    int sum = 0;
    int freq[26] = { 0 };
    for (int i = 0; i < s.length(); i++)
    {
        freq[s[i] - 'a']++;
    }
    for (int i = 0; i < 26; i++)
    {
        if (freq[i] > 0)
            sum++;
    }
    return sum;
}
//function returns the sum of the digits of a number
int getSum(int n)
{
    int sum = 0;
    while (n != 0) {
        sum = sum + n % 10;
        n = n / 10;
    }
    return sum;
}

	 	    	     	  				 	 	  	  		


Comments

Submit
0 Comments
More Questions

550B - Preparing Olympiad
939B - Hamster Farm
732A - Buy a Shovel
1220C - Substring Game in the Lesson
452A - Eevee
1647B - Madoka and the Elegant Gift
1408A - Circle Coloring
766B - Mahmoud and a Triangle
1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold
1515B - Phoenix and Puzzle
155A - I_love_username
49A - Sleuth
1541A - Pretty Permutations
1632C - Strange Test
673A - Bear and Game
276A - Lunch Rush
1205A - Almost Equal
1020B - Badge
1353A - Most Unstable Array
770A - New Password
1646B - Quality vs Quantity
80A - Panoramix's Prediction
1354B - Ternary String